import { ApiProperty } from '@nestjs/swagger';
import { IsInt, IsString } from 'class-validator';
import {
  Column,
  CreateDateColumn,
  Entity,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

@Entity()
export class History {
  @ApiProperty({ description: 'id' })
  @IsInt()
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty({ description: '用户id' })
  @IsString()
  @Column()
  userId: string;

  @ApiProperty({ description: '文章id' })
  @IsInt()
  @Column()
  articleId: number;

  @ApiProperty({ description: '文章名称' })
  @IsString()
  @Column()
  articleName: string;

  @ApiProperty({ description: '合辑id' })
  @IsInt()
  @Column()
  gatherId: number;

  @ApiProperty({ description: '合辑封面' })
  @IsString()
  @Column()
  gatherCover: string;

  @ApiProperty({
    description:
      '阅读进度, 阅读到章节的第几段，当前段落进度，共阅读多少秒 {"index":0,"duration":10,"progress":"0%"}',
  })
  @IsString()
  @Column()
  progress: string;

  @ApiProperty({ description: '阅读总时长' })
  @IsInt()
  @Column()
  duration: number;

  @ApiProperty()
  @CreateDateColumn({ type: 'timestamptz', default: () => 'CURRENT_TIMESTAMP' })
  createdAt: string;

  @ApiProperty()
  @UpdateDateColumn({
    type: 'timestamptz',
    default: () => 'CURRENT_TIMESTAMP',
    onUpdate: 'CURRENT_TIMESTAMP',
  })
  updatedAt: string;
}
